package com.dongdongshop.controller;

import com.dongdongshop.admin.vo.TbBrandVO;
import com.dongdongshop.common.Result;
import com.dongdongshop.em.PageRequest;
import com.dongdongshop.em.PageResult;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @PostMapping("findBrandPage")
    public Result brandList(@RequestBody PageRequest<TbBrandVO> tbBrandVO){
        PageResult<TbBrandVO> brandList = brandService.brandList(tbBrandVO);
        return Result.Response(ResultEnum.SUCCESS).setData(brandList);
    }

    @PostMapping("addBrandVO")
    public Result addBrandVO(@RequestBody TbBrandVO brandVO){
        brandService.add(brandVO);
        return Result.Response(ResultEnum.SUCCESS);
    }

    @PostMapping("getById")
    public Result getById(@RequestParam Long id){
        TbBrandVO list = brandService.getById(id);
        return Result.Response(ResultEnum.SUCCESS).setData(list);
    }

    @PostMapping("updateBranVO")
    public Result updateBrandVO(@RequestBody TbBrandVO brandVO){
        brandService.update(brandVO);
        return Result.Response(ResultEnum.SUCCESS);
    }

    @DeleteMapping("delete")
    public Result delete(@RequestParam Long[] ids) {
        brandService.delete(ids);
        return Result.Response(ResultEnum.SUCCESS);
    }
}
